package com.ruoyi.admin.controller;

import com.ruoyi.admin.service.IEventApplyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.EventApply;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报名情况Controller
 * 
 * @author xukai
 * @date 2024-12-22
 */
@RestController
@RequestMapping("/event/apply")
public class EventApplyController extends BaseController
{
    @Autowired
    private IEventApplyService eventApplyService;

    /**
     * 查询报名情况列表
     */
    //@PreAuthorize("@ss.hasPermi('event:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventApply eventApply)
    {
        startPage();
        List<EventApply> list = eventApplyService.selectEventApplyList(eventApply);
        return getDataTable(list);
    }

    /**
     * 导出报名情况列表
     */
    //@PreAuthorize("@ss.hasPermi('event:apply:export')")
    @Log(title = "报名情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EventApply eventApply)
    {
        List<EventApply> list = eventApplyService.selectEventApplyList(eventApply);
        ExcelUtil<EventApply> util = new ExcelUtil<EventApply>(EventApply.class);
        util.exportExcel(response, list, "报名情况数据");
    }

    /**
     * 获取报名情况详细信息
     */
    //@PreAuthorize("@ss.hasPermi('event:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eventApplyService.selectEventApplyById(id));
    }

    /**
     * 新增报名情况
     */
    //@PreAuthorize("@ss.hasPermi('event:apply:add')")
    @Log(title = "报名情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventApply eventApply)
    {
        return toAjax(eventApplyService.insertEventApply(eventApply));
    }

    /**
     * 修改报名情况
     */
    //@PreAuthorize("@ss.hasPermi('event:apply:edit')")
    @Log(title = "报名情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventApply eventApply)
    {
        return toAjax(eventApplyService.updateEventApply(eventApply));
    }

    /**
     * 删除报名情况
     */
    //@PreAuthorize("@ss.hasPermi('event:apply:remove')")
    @Log(title = "报名情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eventApplyService.deleteEventApplyByIds(ids));
    }
}
